//
//  MyCenterViewController.m
//  NewChat
//
//  Created by 马欢 on 16/2/27.
//  Copyright © 2016年 蓝鸥. All rights reserved.
//

#import "MyCenterViewController.h"
#import "MyCenterViewCell.h"
#import "SuggestViewController.h"
#import "SettingsTableViewController.h"
#import "MyButtonView.h"
#import "MyDataViewController.h"
#import "UMSocial.h"

@interface MyCenterViewController ()<UITableViewDataSource,UITableViewDelegate,MyDataViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *myCenterTVC;
@property (weak, nonatomic) IBOutlet UIView *MyCenterView;

@end

@implementation MyCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.title = @"个人中心";
    self.imageName = [NSString stringWithFormat:@"2.jpg"];//数据库调头像图片名
    self.myCenterImageV.image = [UIImage imageNamed:self.imageName];//头像
    self.nickL.text = @"马欢";//从数据库调 昵称
    self.mySex = @"男";//从数据库 调性别
    self.myAge = @"24";//从数据库 调年龄
    self.label1.text = [NSString stringWithFormat:@"%@ %@",self.mySex,self.myAge];
    self.myType = @"双子座";//数据库调星座
    self.label2.text = self.myType;
//    从后往前传值 设置代理
    [MyDataViewController sharedMyDataViewController].delegate = self;
//    将有点击事件的view附在整个大View上
    MyButtonView *myView = [[MyButtonView alloc]initWithFrame:self.MyCenterView.frame];
    myView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:myView];
    [self.view bringSubviewToFront:myView];
    [myView myTarget:self action:@selector(myData)];//添加点击事件
    //    将playerPic设置成圆角
    self.myCenterImageV.layer.masksToBounds = YES;
    self.myCenterImageV.layer.cornerRadius = self.myCenterImageV.frame.size.width/2.0;
    self.label1.layer.masksToBounds = YES;
    self.label1.layer.cornerRadius = 10;
    self.label1.textAlignment = NSTextAlignmentCenter;
    self.label2.layer.masksToBounds = YES;
    self.label2.layer.cornerRadius = 10;
    self.label2.textAlignment = NSTextAlignmentCenter;
    //注册cell
    UINib *nib = [UINib nibWithNibName:@"MyCenterViewCell" bundle:nil];
    [self.myCenterTVC registerNib:nib forCellReuseIdentifier:@"MyCenterListCell"];
//    设置tableView代理
    self.myCenterTVC.dataSource = self;
    self.myCenterTVC.delegate = self;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}
//设置cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCenterViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCenterListCell" forIndexPath:indexPath];
    if (indexPath.row == 0) {
        cell.label.text = @"分享";
    }else if (indexPath.row == 1){
        cell.label.text = @"意见反馈";
    }else if (indexPath.row == 2){
        cell.label.text = @"设置";
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
//cell点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        //    //设置分享内容与分享平台
        //    //弹出uiacticityViewCotroller样式的列表
        //
        //    [UMSocialSnsService presentSnsIconSheetView:self appKey:nil shareText:@"我是菜鸡" shareImage:[UIImage imageNamed:@"111.jpg"]
        //                                shareToSnsNames:@[UMShareToQQ,UMShareToQzone, UMShareToSina, UMShareToTencent, UMShareToWechatSession, UMShareToWechatTimeline,UMShareToEmail, UMShareToFacebook] delegate:nil];
        // 图片分享，设置分享类型为图片并传入参数，图片对象在下面分享接口中传入
        
        NSString *shareText = @"友盟社会化组件可以让移动应用快速具备社会化分享、登录、评论、喜欢等功能，并提供实时、全面的社会化数据统计分析服务。 http://www.umeng.com/social";             //分享内嵌文字
        
        UIImage *shareImage = [UIImage imageNamed:@"UMS_social_demo"];          //分享内嵌图片
        
        //调用快速分享接口
        
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:nil
                                          shareText:shareText
                                         shareImage:shareImage
                                    shareToSnsNames:nil
                                           delegate:nil];
    }
    else if (indexPath.row == 1){
        SuggestViewController *suggestVC = [[SuggestViewController alloc]init];
        [self.navigationController pushViewController:suggestVC animated:YES];
    }else if (indexPath.row == 2){
        SettingsTableViewController *settingsTVC = [SettingsTableViewController new];
        [self.navigationController pushViewController:settingsTVC animated:YES];
    }
}
//大view点击事件 跳转到我的资料
-(void)myData{
    MyDataViewController *myDataVC = [MyDataViewController sharedMyDataViewController];
    myDataVC.imageName = self.imageName;//传头像 图片名
    myDataVC.myNick = self.nickL.text;//传昵称
    myDataVC.mySex = self.mySex;//传性别
    myDataVC.myAge = self.myAge;
    myDataVC.myType = self.myType;
    [self.navigationController pushViewController:myDataVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//让代理干活
-(void)myDataWith:(NSString *)nick age:(NSString *)age type:(NSString *)type imageName:(NSString *)imageName sex:(NSString *)sex{
    self.nickL.text = nick;
    self.label1.text = [NSString stringWithFormat:@"%@ %@",sex,age];
    self.label2.text = type;
    self.myCenterImageV.image = [UIImage imageNamed:imageName];
    
    self.imageName = imageName;//一定要写，不然多跳转两次 图片就回复默认了
    self.myType = type;
    self.myAge = age;
}

-(void)viewWillAppear:(BOOL)animated{
    [self.tabBarController.tabBar setHidden:NO];
}
@end
